using System;
using System.Collections.Generic;
using System.Text;
using IBatisNet.DataMapper.TypeHandlers;

namespace XBLib.Dal.SqlMapDal
{
    public class EnumerationTypeHandlerCallback<T> : ITypeHandlerCallback
    {
        #region ITypeHandlerCallback Members

        public object GetResult(IResultGetter getter)
        {
            if (getter.Value.ToString() == string.Empty)
                return null;
            return Enum.Parse(typeof(T), getter.Value.ToString());
        }

        public object NullValue
        {
            get { return null; }
        }

        public void SetParameter(IParameterSetter setter, object parameter)
        {
            setter.Value = parameter.ToString();
        }

        public object ValueOf(string s)
        {
            return Enum.Parse(typeof(T), s);
        }

        #endregion
    }
}
